<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="custom" tagdir="/WEB-INF/tags" %>
<html>
<head>
    <title>文章列表</title>
</head>

<body>
<div class="pageheader">
    <h2>文章列表</h2>
</div>
<div class="contentpanel">
    <form class="form-inline">
        <div class="btn-group mr10">
            <input type="text" class="form-control " name="title" value="${listDto.title}"
                   placeholder="请输入要查询的文章标题">
            <select class="form-control" name="publish">
                <option value="1" ${listDto.publish eq "1"?"selected":""}>发布</option>
                <option value="0" ${listDto.publish eq "0"?"selected":""}>未发布</option>
            </select>
            <input type="text" class="form-control " name="name" value="${listDto.name}"
                   placeholder="创建人">
            <button type="submit" class="form-control btn-success">查询</button>
        </div>
        <div class="btn-group mr10">
            <a href="${contextPath}/admin/article/edit.htm" class="btn btn-primary" type="button">
                <i class="fa fa-pencil mr5"></i>添加文章
            </a>
        </div>
    </form>

    <table class="table table-striped dataTable no-footer" id="table2" role="grid" aria-describedby="table2_info">
        <thead>
        <tr role="row">
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                标题
            </th>
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                创建时间
            </th>
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                最后修改日期
            </th>
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                发布状态
            </th>
            <th class="sorting_asc" tabindex="0" aria-controls="table2"
                rowspan="1" colspan="1" aria-sort="ascending">
                创建人
            </th>
            <th class="sorting" tabindex="0" aria-controls="table2" rowspan="1" colspan="1">
                操作
            </th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${listDto.list}" var="item" varStatus="status">
            <tr class="gradeA ${status.index/2 eq 0?"odd":"even"}">
                <custom:article_list_item item="${item}"/>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <custom:page page="${listDto}"/>
    <c:if test="${not empty param.edit}">
        <script type="text/javascript">
            jQuery.gritter.add({
                title: '新增/编辑 成功!',
                class_name: "growl-success",
                sticky: false
            });
        </script>
    </c:if>
    <c:if test="${not empty param.delete}">
        <script type="text/javascript">
            jQuery.gritter.add({
                title: '删除 成功!',
                class_name: "growl-success",
                sticky: false
            });
        </script>
    </c:if>
</div>
<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
<script src="${contextPath}/resources/js/jquery.datatables.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery('#table2').dataTable({
            "bPaginate": false,// 分页按钮
            "bFilter": false,// 搜索栏
            "bLengthChange": false,// 每行显示记录数
            "bInfo": false
        });
    });
    $(".table").on("click", ".ChangeState", function () {
        var uuid = $(this).attr('uuid');
        var title = $(this).attr('title');
        var publish = $(this).attr('publish');
        var tr = $(this).parents("tr");
        //禁用tr
        $(this).addClass("disabled");
        if (confirm('确定变更[' + title + ']的发布状态?')) {
            $.ajax({
                        url: 'change_state',
                        type: "post",
                        data: {uuid: uuid, publish: publish},
                        success: function (data) {
                            tr.html(data);
                        }
                    }
            );
        }
        $(this).removeClass("disabled");
    });

    //加载预览
    $(".loadModal").click(function () {
        var url = $(this).attr("url");
        $(".modal-content").load(url);
    });
</script>
</body>
</html>
